// yecc.c
#include "Yecc.h"

int main(int argc, char *argv[]) {

    char* vanilla = read_source(argv[1]);
    char* src = preprocessor(vanilla);
    struct Token* head = Lexer(src);
    struct Node* root = Parser(head);
    Codegen(root);

    return 0;
}

char* read_source(const char* path) {

    FILE *fp = fopen(path, "r");
    assert(fp != NULL);

    int size = 256 * 1024 * 1024; // 256MB
    char* vanilla = (char*)malloc(size * sizeof(char));
    assert(vanilla != NULL);

    int i = 0;
    while (true) {
        char ch;
        int ret = fscanf(fp, "%c", &ch);
        if(ret == EOF) break;
        vanilla[i++] = ch;
    }
    vanilla[i] = '\0';
    fclose(fp);

    return vanilla;
}
